<!doctype html>
<html  class="x-admin-sm" lang="ch">
<head>
	<meta charset="UTF-8">
	<title>后台登录</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="css/font.css">
	<link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
    <script type="text/javascript" src="js/address.js"></script>
    <script type="text/javascript" src="js/cookie.js"></script>
</head>
<body class="login-bg">
    
    <div class="login layui-anim layui-anim-up">
        <div class="message">后台登录</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form">
            <input id="id" name="id" placeholder="用户名"  type="text" lay-verify="id" class="layui-input" >
            <hr class="hr15">
            <input id="password" name="password" lay-verify="password" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <button type="button" id="submit" style="background-color: #009688;margin-left: auto;width: 100%;height: 40px;font-size: medium;color: white">登录</button>
            <hr class="hr20" >
            <a href="register.html">没有账号？去注册</a>
        </form>
    </div>

    <script>
        $(function() {
            $("#submit").click(function () {
                var id=$("#id").val();
                var password=$("#password").val();
                $.ajax({
                    url: address + "user/login",
                    dataType:"json",
                    type:"post",
                    contentType : "application/json; charset=utf-8",
                    data: JSON.stringify({"phone":id,"password":password}),
                    success:function (data) {
                        window.location.href="index.html?" + data.sessionId;
                    },
                    error:function () {
                        alert("error");
                    }
                });
            });
            // layui.use('form', function(){
            //     var form = layui.form;
            //     var $ = layui.$;
            //     form.on('submit(login)', function(data){
            //         var url = "http://localhost:8080/user/doLogin/"
            //             + data.field.username + "/" + data.field.password;
            //         $.post(url,null,function (data) {
            //             location.href='index.html'
            //             }
            //         ).fail(function (jqXHR) {
            //             layer.msg(jqXHR.responseText);
            //         });
            //         return false;
            //   });
            // });
        });
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form,layer = layui.layer;
            //自定义验证规则
            form.verify({
                id: function(value){
                    if(value === '' || value === null){
                        return '账号不能为空';
                    }
                }
                ,password: function(value){
                    if(value === '' || value === null){
                        return '密码不能为空';
                    }
                }
            });
        });
    </script>
</body>
</html>